<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;

/* @var $this yii\web\View */
/* @var $searchModel common\models\qywx\QywxAccessTokenSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Qywx Access Tokens');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="qywx-access-token-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Qywx Access Token'), ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Get Access Token'), ['retrieve'], ['class' => 'btn btn-primary']) ?>
    </p>
    <?php
    try {
        $gv = GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                [
                    'class' => 'yii\grid\ActionColumn',
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
                ],
//                [
//                    'class' => 'yii\grid\SerialColumn',
//                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
//                ],
//                'id',
                [
                    'label' => Yii::t('app', 'App Id'),
                    'attribute' => 'app_id',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'attribute' => 'val',
                    'value' => function ($model, $key, $index, $column) {
                        return \common\helpers\StringUtil::getShortString($model['val'], 100);
                    },
//                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 200px;'],
//                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'white-space: normal; width: 200px;'],
                ],
//                [
//                    'attribute' => 'val',
//                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 200px;'],
//                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'white-space: normal; width: 200px;'],
//                ],
                [
//                    'label' => Yii::t('app', 'App Id'),
                    'attribute' => 'expires_in',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'attribute' => 'status',
                    'value' => function ($model, $key, $index, $column) {
                        return EhrHelper::getAccessTokenByIntValue($model['status']);
                    },
                    'filter' => EhrHelper::getAccessTokenStatus_map(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                // 'errcode',
                // 'errmsg',
                // 'created_by',
                [
//                    'label' => Yii::t('app', 'App Id'),
                    'attribute' => 'created_at',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                // 'updated_by',
                // 'updated_at',
            ],
        ]);
    } catch (Exception $e) {
    }
    ?>
    <?= $gv ?>
</div>
